#!/usr/bin/env python
# coding=utf-8
import os
import sys

basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

# SQLite URI compatible
WIN = sys.platform.startswith('win')
if WIN:
    prefix = 'sqlite:///'
else:
    prefix = 'sqlite:////'


class BaseConfig(object):
    SECRET_KEY = os.getenv('SECRET_KEY', 'devkey')

    DEBUG_TB_INTERCEPT_REDIRECTS = False

    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_RECORD_QUERIES = True

    CKEDITOR_ENABLE_CSRF = True
    CKEDITOR_FILE_UPLOADER = 'admin.upload_image'

    MAIL_SERVER = os.getenv('MAIL_SERVER', 'smtp.qq.com')
    MAIL_PORT = 465
    MAIL_USE_SSL = True
    MAIL_USERNAME = os.getenv('MAIL_USERNAME')
    MAIL_PASSWORD = os.getenv('MAIL_PASSWORD')
    MAIL_DEFAULT_SENDER = ('FILESHARE Admin', MAIL_USERNAME)
    ADMIN_EMAIL = os.getenv('ADMIN_EMAIL', MAIL_USERNAME)

    FILESHARE_EMAIL = os.getenv('FILESHARE_EMAIL')
    FILESHARE_POST_PER_PAGE = 10
    FILESHARE_MANAGE_POST_PER_PAGE = 15
    FILESHARE_COMMENT_PER_PAGE = 15
    # ('theme name', 'display name')
    FILESHARE_THEMES = {'perfect_blue': 'Perfect Blue',
                        'black_swan': 'Black Swan'}
    FILESHARE_SLOW_QUERY_THRESHOLD = 1

    FILESHARE_WORKDIR = os.getenv('FILESHARE_WORKDIR', os.path.sep)  # 初始文件目录
    SECURE_LINK = os.getenv('SECURE_LINK', '')  # 安全链接
    FILESHARE_IS_NETDISC = os.getenv(
        'FILESHARE_IS_NETDISC', True)  # 是否开启网盘模式，每个用户一个文件夹


class DevelopmentConfig(BaseConfig):
    SQLALCHEMY_DATABASE_URI = prefix + os.path.join(basedir, 'data-dev.db')


class TestingConfig(BaseConfig):
    TESTING = True
    WTF_CSRF_ENABLED = False
    SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'  # in-memory database


class ProductionConfig(BaseConfig):
    SQLALCHEMY_DATABASE_URI = os.getenv(
        'DATABASE_URL', prefix + os.path.join(basedir, 'data.db'))


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig
}
